﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using QuanLyBanHang.OBJECT;

namespace QuanLyBanHang.DAL
{
    static class DalLoaiHang
    {
        public static DataTable LoadCategory()
        {
            string sql = "select * from loaihang";
            DataTable dt = DataHelper.Load(sql);
            return dt;
        }
        public static DataTable GetID()
        {
            string sql = "select top 1 MaLH from LoaiHang order by MaLH desc";
            DataTable dt = DataHelper.Load(sql);
            return dt;
        }
        public static int InsertCategory(ObjLoaiHang obj)
        {
            SqlParameter[] para = new SqlParameter[3];
            string[] names = { "MaLH","Ten","GhiChu"};
            object[] values = { obj.Ma, obj.Ten, obj.Ghichu };
            for (int i = 0; i < para.Length; i++)
            {
                para[i] = new SqlParameter(names[i], values[i]);
            }
            int thucthi = DataHelper.Update(para, "spInsertLoaiHang");
            return thucthi;
        }
        public static int UpdateCategory(ObjLoaiHang obj)
        {
            SqlParameter[] para = new SqlParameter[3];
            string[] names = { "MaLH", "Ten", "GhiChu" };
            object[] values = { obj.Ma, obj.Ten, obj.Ghichu };
            for (int i = 0; i < para.Length; i++)
            {
                para[i] = new SqlParameter(names[i], values[i]);
            }
            int thucthi = DataHelper.Update(para, "spUpdateLoaiHang");
            return thucthi;
        }
    }
}
